home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / PrinterClassDriver / Utils.cp < prev    next >
Encoding:
Text File  |  1998-09-03  |  2.7 KB  |  125 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Utils.cp
  3.  
  4.     Contains:    General utilities
  5.  
  6. */
  7. #include "Utils.h"
  8.  
  9.  
  10. /*-----------------------------------------------------------------------------*
  11.  
  12.     PStrEqualCaseInsensitive
  13.     
  14.     Desc:        Compares two Pascal strings while ignoring case
  15.  
  16.     In:            string1 - string to compare
  17.                 string2 - string to compare
  18.     Out:        none
  19.     
  20.     History:
  21.  
  22.     22 Mar 98    gp        Added.
  23.     
  24. *-----------------------------------------------------------------------------*/
  25. Boolean PStrEqualCaseInsensitive( Str255 string1, Str255 string2 )
  26. {
  27.     short    x;
  28.     char    c1, c2;
  29.     
  30.     if ( string1[0] != string2[0] )
  31.         return( false );
  32.         
  33.     for ( x=1; x<=string1[0]; x++ )
  34.     {
  35.         c1 = string1[x];
  36.         c2 = string2[x];
  37.         if ( c1 != c2 )
  38.         {
  39.             c1 &= ~32;
  40.             c2 &= ~32;
  41.             if ( (c1>='A') && (c1<='Z') && (c1 != c2) )
  42.                 return( false );
  43.         }
  44.     }
  45.     return( true );
  46. }
  47.  
  48. /*-----------------------------------------------------------------------------*
  49.  
  50.     AppendPStr
  51.     
  52.     Desc:        Copy a PASCAL style string to the source
  53.  
  54.     In:            mainStr - string to append to
  55.                 addStr - string to append
  56.     Out:        none
  57.     
  58.     History:
  59.  
  60.     22 Mar 98    gp        Added.
  61.     
  62. *-----------------------------------------------------------------------------*/
  63. void AppendPStr(StringPtr mainStr, StringPtr addStr)
  64.     {
  65.     register short    i;
  66.     register unsigned char    *pMainStr    = (unsigned char *)&mainStr[mainStr[0] + 1];
  67.     register unsigned char    *pAddStr    = (unsigned char *)&addStr[1];
  68.     register short    addLength    = (unsigned char)addStr[0];
  69.  
  70.     if (addLength)
  71.         {
  72.         // limit the ultimate length to 255 bytes
  73.         if ( ((unsigned char)mainStr[0] + addLength) > 255)
  74.             addLength    = 255 - (unsigned char)mainStr[0];
  75.  
  76.         // do the copy
  77.         for (i = 0; i < addLength; ++i)
  78.             *pMainStr++    = *pAddStr++;
  79.  
  80.         // update the count
  81.         mainStr[0]    += addLength;
  82.         }
  83.     }
  84.  
  85. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86.     
  87.     NameRegistryInstalled
  88.     
  89.     Desc:    Copies the contents of cell in the list hList into the string
  90.             pointed to by theString. The string is converted to a Pascal-
  91.             style string, with a preceding length byte.
  92.         
  93.         It is assumed that cell is a valid cell, that the cell contains no
  94.         more than 255 characters, and that theString and hList are not nil.
  95.  
  96.  
  97.     In:            Pointer to storage for a string.
  98.                 Coordinates of cell in list
  99.                 Handle to list
  100.  
  101.     Out:        String containing copy of cell text
  102.     
  103.     History:
  104.  
  105.             22 Mar 98    gp        Added.
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  107. void GetNameFromCell (StringPtr theString, Cell cell, ListHandle hList)
  108. {
  109.     short length;
  110.     
  111.     /*
  112.     The maximum length of the string is the size of a Str255, minus the
  113.     length byte…
  114.     */
  115.     length = sizeof(Str255) - 1;
  116.  
  117.     LGetCell((StringPtr)(theString + 1), &length, cell, hList);
  118.     
  119.     /*
  120.     Set the length byte.
  121.     */
  122.     *theString = (unsigned char) length;
  123. };
  124.  
  125.